package com.easyctrl.adapter;

import java.util.ArrayList;

import com.easyctrl.iface.FRMAdapterListener;
import com.easyctrl.ldy.activity.R; 

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox; 
import android.widget.TextView; 

public class FRMAdapter<T> extends BaseAdapter {

	private ArrayList<T> deletes;
	private ArrayList<T> beans;
	private FRMAdapterListener adapterListener;
	
	public void setAdapterListener(FRMAdapterListener adapterListener) {
		this.adapterListener = adapterListener;
	}

	private LayoutInflater mInflater;   
	public ArrayList<T> getDeletes() {
		return deletes;
	}
	public void setBeans(ArrayList<T> beans) {
		this.beans = beans;
	} 
	public FRMAdapter(Context context){
		this.mInflater = LayoutInflater.from(context);
		deletes = new ArrayList<T>();
	}

	@Override
	public int getCount() {
		return beans == null ? 0 : beans.size();
	}

	@Override
	public Object getItem(int position) {
		return beans.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.floor_room_item, parent,false);
			holder.delete = (CheckBox) convertView.findViewById(R.id.delete);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			holder.num = (TextView) convertView.findViewById(R.id.num);
			holder.use = (TextView) convertView.findViewById(R.id.use);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		} 
		adapterListener.onGetView(holder, position,beans);
		
		return convertView;
	}

	public class ViewHolder {
		public TextView num;
		public CheckBox delete;
		public TextView name;
		public TextView use;
	}
}
